﻿/*
创建人：longb
日期：2022-06-06
描述：质量问题处置js
*/
var page = {
    workflowstepid: getParam("id"),
    ContainerNo: getParam("ContainerNo"),
    rootPath: getRootPath(), //网站根路径
    ajaxUrl: getRootPath() + "/Ashx/ZsHandler/ZSContainerCheckInfoManageHandler.ashx",
    comboxUrl: getRootPath() + "/Ashx/ZsHandler/ZSContainerCheckInfoManageHandler.ashx", //combox下拉-调用后台的URL
    comboxAction: "GetEmployees", //combox下拉-调用后台的具体方法
    //初始化页面
    init: function () {
        page.bind();
        page.GetSpecData();
        page.GetBigSmallData();
        page.InitUnit();
    },
    //页面事件绑定
    bind: function () {
        $('.DUTYEMPLOYEEID').selectCombox({
            search: function () { },
            cancel: function () { },
            selected: function (val, text, record) {
                $('#DUTYEMPLOYEEID').val(val);
                $('#txtCombox').textbox('setValue', text);
                $('#divComboxTxt').show();
                $('#divComboxSelect').hide();
                $('#divComboxSearch').show();
                $('#divComboxClear').hide();
            }
        });
        //配套件信息
        $('#BigTabel').datagrid({
            checkOnSelect: false,
            selectOnCheck: false,
            singleSelect: true,
            rownumbers: true,
            columns: [[
		            { field: 'PRODUCTNAME', title: '零件图号', width: 100, align: 'center' },
		            { field: 'QTYREQUIRED', title: '需求数量', width: 100, align: 'center' },
                    { field: 'PRODUCTBATCHNO', title: '批次号', width: 100 },
                    { field: 'ISSUEQTY', title: '配套数量', width: 100, align: 'center' },
                    { field: 'CONFIRMQTY', title: '实装数量', width: 100, align: 'center' },
                    { field: 'LOSSQTY', title: '报废数量', width: 100, align: 'center' },
                    { field: 'STATUS', title: '创建周转状态', width: 100, align: 'center' },
                    { field: 'DEALSTATUS', title: '排故单', width: 100, align: 'center' }
                ]],
            onSelect: function (index, row) {
                $('#DealForm').form('load', row);
                $('#productItemName').textbox('setValue', row.PRODUCTNAME);
                $('#MachineTotalNum').textbox('setValue', row.QTYREQUIRED);
                page.GetQulityQuestionDeal();
            }
        });
        $('#PartCategory').combobox({
            data: [{ id: '01', text: '关键件' }, { id: '02', text: '重要件' }, { id: '03', text: '一般件' }, { id: '04', text: '试验件'}],
            valueField: 'id',
            textField: 'text'
        });
        $('#PartCategory').combobox("setValue", "03");
        $('#problemNature').combobox({
            data: [{ id: '10', text: '重大' }, { id: '20', text: '严重' }, { id: '30', text: '一般A类外场' }, { id: '40', text: '一般A类厂内' }, { id: '50', text: '一般A类厂内'}],
            valueField: 'id',
            textField: 'text'
        });
        $('#problemNature').combobox("setValue", "50");
    },
    //查询工序信息
    GetSpecData: function () {
        var param = {
            action: "GetSpecData"
        };
        page.post(param, function (res) {
            if (res.ReturnData != null) {
                $('#SpecForm').form('load', res.ReturnData);
                $('#ProductFamilyName').textbox('setValue', res.ReturnData.ProductFamilyName); //产品型号
                //$('#ContainerNo').textbox('setValue', res.ReturnData.ContainerNo); //批次流水卡
                $('#productItemName').textbox('setValue', res.ReturnData.ProductName);
                $('#PDESC').textbox('setValue', res.ReturnData.ProductDesc);
                $('#PRODUCTBATCHNO').textbox('setValue', res.ReturnData.machinepname);
                $('#MaterialTrademark').textbox('setValue', res.ReturnData.MaterialTrademark); //材料牌号
                $('#Part_RevID').textbox('setValue', res.ReturnData.Part_RevID); //图纸版次
            }
        });
    },
    //查询配套件信息
    GetBigSmallData: function () {
        var param = {
            action: "GetBigSmallData",
            workflowstepid: page.workflowstepid,
            ContainerNo: page.ContainerNo
        };
        page.post(param, function (res) {
            $('#BigTabel').datagrid('loadData', res.DBTable);
            if (res.Result) {

            }
        });
    },
    ///初始化责任单位
    InitUnit: function () {
        page.post({ action: "GetUnit" }, function (res) {
            $('#FactoryID').combobox({
                data: res.DBTable,
                valueField: 'FACTORYID',
                textField: 'FACTORYNAME'
            });
            $('#FactoryID').combobox('setValue', res.DBTable[0].FACTORYID);
        });
    },
    //获取处置单信息
    GetQulityQuestionDeal: function () {
        var row = $('#BigTabel').datagrid("getSelected");
        var param = {
            action: "GetQulityQuestionDeal",
            productitemname: row.PRODUCTNAME,
            issueerpmalterialid: row.ISSUEERPMATERIALID,
            togetherflag: $('#togetherflag').textbox('getValue')
        };
        page.post(param, function (res) {
            if (res.DBTable.length > 0) {
                var data = res.DBTable[0];
                $('#DealForm').form('load', { QUALITYHISTORYRECORDID: data.QUALITYHISTORYRECORDID, UnqualifiedNum: data.UNQUALIFIEDNUM, CheckNO: data.CHECKNO, PartCategory: data.PARTCATEGORY, FactoryID: data.FACTORYID });
                $('#UnqualifiedForm').form('load', { UnqualifiedDescribe: data.UNQUALIFIEDDESCRIBE, IsKeyFeatures: data.ISKEYFEATURES, IsImportantFeatures: data.ISIMPORTANTFEATURES, IsDesignBasisFeatures: data.ISDESIGNBASISFEATURES });
            } else {
                $('#DealForm').form('load', { QUALITYHISTORYRECORDID: '', UnqualifiedNum: '', CheckNO: '', PartCategory: '03' });

                $('#UnqualifiedForm').form('clear');
                $('#UnqualifiedForm').form('load', { IsKeyFeatures: '0', IsImportantFeatures: '0', IsDesignBasisFeatures: '0' });
            }
        });
    },
    //提交处置单信息
    QulityQuestionDeal: function () {
        var frdata = $('#DealForm').serializeArray();
        var data = {};
        $.each(frdata, function () {
            data[this.name] = this.value
        });
        var frdata1 = $('#UnqualifiedForm').serializeArray();
        $.each(frdata1, function () {
            data[this.name] = this.value
        });
        data["productname"] = $('#ProductName').textbox('getValue');
        data["engineno"] = $('#machinepname').textbox('getValue');
        data["togetherflag"] = $('#togetherflag').textbox('getValue');
        data["mfgOrderName"] = $('#mfgOrderName').textbox('getValue');
        data["workflowstepid"] = page.workflowstepid;
        if (data["productItemName"] == "") { displayMessage("零件图号不能为空，请选择零件", false); return; }
        if (data["UnqualifiedNum"] == "") { displayMessage("不合格品数不能为空，请输入数量", false); return; }
        if (Number(data["UnqualifiedNum"]) > Number(data["MachineTotalNum"])) { displayMessage("不合格品数不能大于总数，请重新输入数量", false); return; }
        if (data["DUTYEMPLOYEEID"] == "") { displayMessage("责任者不能为空，请选择", false); return; }
        if (data["UnqualifiedDescribe"] == "") { displayMessage("不合格描述不能为空，请输入", false); return; }
        var param = {
            action: "SaveQulityQuestionDeal",
            data: JSON.stringify([data])
        };
        page.post(param, function (res) {
            displayMessage(res.Message, res.Result);
        });

    },
    //清除方法，重要！！！
    reset: function (iscondition, isresult) {
        clearMessage();
    },
    //post数据
    post: function (param, callback) {
        $.ajax({
            type: "Post",
            url: page.ajaxUrl,
            data: param,
            cashe: false,
            async: true,
            dataType: "json",
            beforeSend: function () {
                $.messager.progress({ text: '', msg: '处理中...' });
            },
            success: function (data) {
                $.messager.progress('close');
                callback(data);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.messager.progress('close');
                displayMessage(XMLHttpRequest.responseText, false);
            }
        });
    }
}
$(function () {
    page.init();
});